<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"> <style>
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='line'>  1</span> <span class="WHIT">
<span class='line'>  2</span> </span><span class="COMM">/**
<span class='line'>  3</span>  * @fileoverview Simple bubble chart implementation.
<span class='line'>  4</span>  * @version 1.0.1
<span class='line'>  5</span>  * @link http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml
<span class='line'>  6</span>  * @link https://developers.google.com/closure/compiler/docs/js-for-compiler
<span class='line'>  7</span>  */</span><span class="WHIT">
<span class='line'>  8</span> 
<span class='line'>  9</span> 
<span class='line'> 10</span> 
<span class='line'> 11</span> </span><span class="COMM">/**
<span class='line'> 12</span>  * FunnelChart constructor.
<span class='line'> 13</span>  * @param {string|Element} container The HTML container.
<span class='line'> 14</span>  * @constructor
<span class='line'> 15</span>  * @extends {charts.BubbleChart} charts.BubbleChart
<span class='line'> 16</span>  * @example
<span class='line'> 17</span>  * &lt;b>var&lt;/b> chart = &lt;b>new&lt;/b> charts.FunnelChart('container_id');
<span class='line'> 18</span>  * chart.draw([['ID',   'Temperature'],
<span class='line'> 19</span>  *             ['USA',            120],
<span class='line'> 20</span>  *             ['CAN',             50],
<span class='line'> 21</span>  *             ['RUS',             80],
<span class='line'> 22</span>  *             ['GBR',             40]
<span class='line'> 23</span>  * ]);
<span class='line'> 24</span>  *
<span class='line'> 25</span>  * &lt;div id="chart-container"
<span class='line'> 26</span>  *      style="width: 560px; height: 300px; margin-left: 20px;">&lt;/div>
<span class='line'> 27</span>  * &lt;script src="../../bin/jscb.js">&lt;/script>
<span class='line'> 28</span>  * &lt;script>
<span class='line'> 29</span>  *   var chart = new charts.FunnelChart('chart-container');
<span class='line'> 30</span>  *   chart.draw([['ID',   'Temperature'],
<span class='line'> 31</span>  *               ['USA',            120],
<span class='line'> 32</span>  *               ['CAN',             50],
<span class='line'> 33</span>  *               ['RUS',             80],
<span class='line'> 34</span>  *               ['GBR',             40]
<span class='line'> 35</span>  *   ]);
<span class='line'> 36</span>  * &lt;/script>
<span class='line'> 37</span>  */</span><span class="WHIT">
<span class='line'> 38</span> </span><span class="NAME">charts.FunnelChart</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">container</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 39</span> </span><span class="WHIT">  </span><span class="NAME">charts.BubbleChart.apply</span><span class="PUNC">(</span><span class="KEYW">this</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">arguments</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 40</span> 
<span class='line'> 41</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'> 42</span>    * Saved reference to charts.BubbleChart.draw method.
<span class='line'> 43</span>    * @type {!function(!Array.&lt;Array>, Object=)}
<span class='line'> 44</span>    * @private
<span class='line'> 45</span>    */</span><span class="WHIT">
<span class='line'> 46</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">draw_</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.draw</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 47</span> 
<span class='line'> 48</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'> 49</span>    * Draws the chart based on &lt;code>data&lt;/code> and &lt;code>opt_options&lt;/code>.
<span class='line'> 50</span>    * @param {!Array.&lt;Array>} data A chart data.
<span class='line'> 51</span>    * @param {Object=} opt_options A optional chart's configuration options.
<span class='line'> 52</span>    * @override
<span class='line'> 53</span>    */</span><span class="WHIT">
<span class='line'> 54</span> </span><span class="WHIT">  </span><span class="NAME">this.draw</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">data</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">opt_options</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 55</span> </span><span class="WHIT">    </span><span class="NAME">opt_options</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">getOptions_</span><span class="PUNC">(</span><span class="NAME">opt_options</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 56</span> 
<span class='line'> 57</span> </span><span class="WHIT">    </span><span class="COMM">/** @type {number} */</span><span class="WHIT"> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">index</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">data</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">.</span><span class="NAME">length</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 58</span> </span><span class="WHIT">    </span><span class="COMM">/** @type {!Array.&lt;number>} */</span><span class="WHIT">
<span class='line'> 59</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">range</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">self_.getDataRange</span><span class="PUNC">(</span><span class="NAME">data</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">index</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 60</span> 
<span class='line'> 61</span> </span><span class="WHIT">    </span><span class="COMM">/** @type {number} */</span><span class="WHIT"> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">width</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">self_.container.offsetWidth</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NUMB">200</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 62</span> </span><span class="WHIT">    </span><span class="COMM">/** @type {number} */</span><span class="WHIT"> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">height</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">self_.container.offsetHeight</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">width</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 63</span> </span><span class="WHIT">    </span><span class="COMM">/** @type {number} */</span><span class="WHIT"> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">limit</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">Math.min</span><span class="PUNC">(</span><span class="NAME">width</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">height</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 64</span> 
<span class='line'> 65</span> </span><span class="WHIT">    </span><span class="COMM">/** @type {!Array.&lt;Array>} */</span><span class="WHIT">
<span class='line'> 66</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">result</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">getBubbleChartData_</span><span class="PUNC">(</span><span class="NAME">data</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">range</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">limit</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">index</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">width</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 67</span> </span><span class="WHIT">    </span><span class="NAME">draw_</span><span class="PUNC">(</span><span class="NAME">result</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">opt_options</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 68</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 69</span> 
<span class='line'> 70</span> </span><span class="WHIT">  </span><span class="COMM">// Export for closure compiler.</span><span class="WHIT">
<span class='line'> 71</span> </span><span class="WHIT">  </span><span class="KEYW">this</span><span class="PUNC">[</span><span class="STRN">'draw'</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.draw</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 72</span> 
<span class='line'> 73</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'> 74</span>    * @param {!Array.&lt;Array>} data A chart data.
<span class='line'> 75</span>    * @param {number} maxValue The max value.
<span class='line'> 76</span>    * @param {number} limit The radius limit.
<span class='line'> 77</span>    * @param {number} index The value column index.
<span class='line'> 78</span>    * @param {number} center The center X coordinate.
<span class='line'> 79</span>    * @return {!Array.&lt;Array>} Returns data converted to BubbleChart data format.
<span class='line'> 80</span>    * @private
<span class='line'> 81</span>    */</span><span class="WHIT">
<span class='line'> 82</span> </span><span class="WHIT">  </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">getBubbleChartData_</span><span class="PUNC">(</span><span class="NAME">data</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">maxValue</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">limit</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">index</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">center</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 83</span> </span><span class="WHIT">    </span><span class="COMM">/** @type {!Array.&lt;Array>} */</span><span class="WHIT">
<span class='line'> 84</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">result</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">[</span><span class="NAME">data</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">''</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">''</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">[</span><span class="NAME">index</span><span class="PUNC">]</span><span class="PUNC">]</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 85</span> </span><span class="WHIT">    </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="COMM">/** @type {number} */</span><span class="WHIT"> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">data.length</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 86</span> </span><span class="WHIT">      </span><span class="COMM">/** @type {Array} */</span><span class="WHIT"> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">row</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 87</span> </span><span class="WHIT">      </span><span class="COMM">/** @type {number} */</span><span class="WHIT"> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">value</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">row</span><span class="PUNC">[</span><span class="NAME">index</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 88</span> </span><span class="WHIT">      </span><span class="COMM">/** @type {number} */</span><span class="WHIT"> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">y</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">Math.sqrt</span><span class="PUNC">(</span><span class="NAME">value</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NAME">Math.PI</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT">
<span class='line'> 89</span> </span><span class="WHIT">          </span><span class="NAME">Math.sqrt</span><span class="PUNC">(</span><span class="NAME">maxValue</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NAME">Math.PI</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">limit</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 90</span> </span><span class="WHIT">          </span><span class="NAME">value</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">result.push</span><span class="PUNC">(</span><span class="PUNC">[</span><span class="NAME">row</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">center</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">y</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">value</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 91</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 92</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">result</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 93</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 94</span> 
<span class='line'> 95</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'> 96</span>    * Gets chart's options merged with defaults chart's options.
<span class='line'> 97</span>    * @param {Object=} opt_options A optional chart's configuration options.
<span class='line'> 98</span>    * @return {!Object.&lt;string, *>} A map of name/value pairs.
<span class='line'> 99</span>    * @private
<span class='line'>100</span>    */</span><span class="WHIT">
<span class='line'>101</span> </span><span class="WHIT">  </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">getOptions_</span><span class="PUNC">(</span><span class="NAME">opt_options</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>102</span> </span><span class="WHIT">    </span><span class="NAME">opt_options</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">opt_options</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>103</span> </span><span class="WHIT">    </span><span class="NAME">opt_options</span><span class="PUNC">[</span><span class="STRN">'hAxis'</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>104</span> </span><span class="WHIT">    </span><span class="NAME">opt_options</span><span class="PUNC">[</span><span class="STRN">'vAxis'</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>105</span> </span><span class="WHIT">    </span><span class="NAME">opt_options</span><span class="PUNC">[</span><span class="STRN">'limit'</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">100</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="COMM">// Radius limit in percents.</span><span class="WHIT">
<span class='line'>106</span> </span><span class="WHIT">    </span><span class="NAME">opt_options</span><span class="PUNC">[</span><span class="STRN">'funnel'</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>107</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">opt_options</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>108</span> </span><span class="WHIT">    </span><span class="COMM">// return self_.getOptions(opt_options);</span><span class="WHIT">
<span class='line'>109</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>110</span> 
<span class='line'>111</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'>112</span>    * The reference to current class instance. Used in private methods.
<span class='line'>113</span>    * @type {!charts.FunnelChart}
<span class='line'>114</span>    * @private
<span class='line'>115</span>    */</span><span class="WHIT">
<span class='line'>116</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">self_</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>117</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>118</span> 
<span class='line'>119</span> </span><span class="COMM">// Export for closure compiler.</span><span class="WHIT">
<span class='line'>120</span> </span><span class="NAME">charts</span><span class="PUNC">[</span><span class="STRN">'FunnelChart'</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">charts.FunnelChart</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>121</span> </span></pre></body></html>